<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org" xmlns:t="http://www.w3.org/1999/xhtml">
<head th:replace="components/easyui/easyui-list :: head('quartz任务', 'easyui')">
<body>
<div id="tb">
    <div class="datagrid-toolbar" style="padding-bottom: 6px">
        类名: <input class="easyui-textbox" style="width: 160px" id="search_beanName" name="beanName" data-options="required:false">
        任务状态: <t:dict class="easyui-combobox" id="search_jobStatus" name="jobStatus" dict-name="job_status"  style="width:160px" allow-empty="true"></t:dict>
        <a href="javascript:void(0)" class="easyui-linkbutton c-primary" style="width:80px" onclick="doSearch()"><i class="fa fa-search" aria-hidden="true"></i> <span th:text="#{search}"></span></a>
        <a href="javascript:void(0)" class="easyui-linkbutton c-basic" style="width:80px" onclick="doSearchReset()"><i class="fa fa-repeat" aria-hidden="true"></i> <span th:text="#{reset}"></span></a>
    </div>
    <div class="datagrid-toolbar easyui-panel" style="padding:5px;">
        <a th:if="${#authorization.expression('hasAnyRole(''__${add}__'')')}" href="javascript:void(0)" class="easyui-linkbutton c-primary" style="width:80px" data-options="toggle:true,group:'g1'" onclick="doAdd()"><i class="fa fa-plus" aria-hidden="true"></i> <span th:text="#{add}"></span></a>
        <a th:if="${#authorization.expression('hasAnyRole(''__${edit}__'')')}" href="javascript:void(0)" class="easyui-linkbutton c-warning" style="width:80px" data-options="toggle:true,group:'g1'" onclick="doEdit()"><i class="fa fa-pencil" aria-hidden="true"></i> <span th:text="#{edit}"></span></a>
        <a th:if="${#authorization.expression('hasAnyRole(''__${delete}__'')')}" href="javascript:void(0)" class="easyui-linkbutton c-danger" style="width:80px" data-options="toggle:true,group:'g1'" onclick="doDelete()"><i class="fa fa-trash" aria-hidden="true"></i> <span th:text="#{delete}"></span></a>
    </div>
</div>
<table id="tt">
    <thead>
    <tr>
        <th data-options="field:'ck',checkbox:true"></th>
        <th data-options="width:200,sortable:true,align:'center',hidden:false,field:'id'">id</th>
        <th data-options="width:200,sortable:true,align:'center',hidden:true,field:'createBy'">创建人id</th>
        <th data-options="width:200,sortable:true,align:'center',hidden:true,field:'createDate'">创建时间</th>
        <th data-options="width:200,sortable:true,align:'center',hidden:true,field:'updateBy'">更新人id</th>
        <th data-options="width:200,sortable:true,align:'center',hidden:true,field:'updateDate'">更新时间</th>
        <th data-options="width:200,sortable:true,align:'center',hidden:false,field:'cronExpression'">cron表达式</th>
        <th data-options="width:200,sortable:true,align:'center',hidden:false,field:'methodName'">任务调用的方法名</th>
        <th data-options="width:200,sortable:true,align:'center',hidden:false,field:'isConcurrent'">任务是否有状态</th>
        <th data-options="width:200,sortable:true,align:'center',hidden:false,field:'description'">描述</th>
        <th data-options="width:200,sortable:true,align:'center',hidden:false,field:'beanName'">任务执行时调用哪个类的方法 包名+类名，完全限定名</th>
        <th data-options="width:200,sortable:true,align:'center',hidden:false,field:'triggerName'">触发器名称</th>
        <th data-options="width:200,sortable:true,align:'center',hidden:false,field:'jobStatus',formatter:formatJobStatus">任务状态</th>
        <th data-options="width:200,sortable:true,align:'center',hidden:false,field:'springBean'">spring_bean</th>
        <th data-options="width:200,sortable:true,align:'center',hidden:false,field:'jobName'">任务名</th>
        <th data-options="width:200,sortable:true,align:'center',hidden:false,field:'operation',formatter:formatJobAction">操作</th>
    </tr>
    </thead>
</table>
<div id="dlg" class="easyui-dialog" data-options="title:'图片信息',closed:true,border:false" style="width:480px;height:480px;padding:10px"></div>
<div id="window_content" class="easyui-window" title="内容详情" data-options="modal:true,closed:true,collapsible:false,border:false" style="width:720px;height:480px;padding:10px;"></div>
<div th:replace="components/easyui/easyui-list :: js('easyui')"></div>
<script th:inline="javascript">
    /*<![CDATA[*/
    $(function () {
        $('#tt').datagrid({
            url: '/api/quartzJobs/data',
            method: 'get',
            idField: 'id',
            nowrap: false,
            animate: true,
            rownumbers: true,
            fit: true,
            toolbar: '#tb',
            pagination: true,
            singleSelect: false,
            selectOnCheck: true,
            checkOnSelect: true
        });
    });

    function doSearch() {
        $('#tt').datagrid('load', {
            beanName: $('#search_beanName').val(),
            jobStatus: $('#search_jobStatus').val(),
        });
    }

    function doSearchReset() {
        $('#search_beanName').textbox('setValue', '');
        $('#search_jobStatus').combobox('select', '');
        doSearch();
    }

    function doAdd() {
        parent.showWindow({
            title:'录入',
            content:'/api/quartzJobs/add'
        });
    }

    function doEdit() {
        //获取选中的第一行数据
        //var row = $('#tt').datagrid('getSelected');
        //获取选中的所有行数据
        let rows = $('#tt').datagrid('getSelections');
        if(rows.length == 1){
            let row = rows[0];
            parent.showWindow({
                title:'编辑',
                content:'/api/quartzJobs/edit?id=' + row.id
            });
        }else{
            $.messager.alert('提示信息','请选择一条数据！','error');
        }
    }

    function doDelete() {
        deleteRequest('/api/quartzJobs/ids/');
    }

    function formatIcon(val, row){
        return '<i class="' + val + '" aria-hidden="true"></i>';
    }

    function formatPic(val, row) {
        if(!val){
            return '';
        }
        return '<img class="image-thumb" src="' + [[${filePathPrefix}]] + val + '" alt="头像" width="30px">';
    }

    function formatContent(val, row) {
        console.log(row.id.toString());
        return "<a href=\"javascript:void(0)\" class=\"button button-rounded button-small button-primary\" onclick='showContent(\""  + row.id.toString() + "\")'>查看</a>";
    }

    function showContent(val) {
        let rows = $('#tt').datagrid('getSelections');
        $('#window_content').html(rows[0].content);
        $('#window_content').window('open');
    }

    function formatJobStatus(value, row) {
        let jobStatusList = [[${jobStatusList}]];
        for(let i = 0; i < jobStatusList.length; i++){
            if(String(value) == String(jobStatusList[i].typeCode)){
                return jobStatusList[i].typeName;
            }
        }
        return value;
    }

    function formatJobAction(val, row) {
        return '<button class="button button-circle button-small button-action" onclick="jobOn(' + row.id + ')"><i class="fa fa-play" aria-hidden="true"></i></button>'
            + ' <button class="button button-circle button-small button-highlight" onclick="jobOff(' + row.id + ')"><i class="fa fa-stop" aria-hidden="true"></i></button>'
            + ' <button class="button button-circle button-small button-royal"><i class="fa fa-pencil" aria-hidden="true"></i></button>'
            + ' <button class="button button-circle button-small button-caution"><i class="fa fa-trash" aria-hidden="true"></i></button>';
    }

    function jobOn(id) {
        commonRequest({
            url: '/api/quartzJobs/id/' + id + '/jobStatus/1',
            type: 'POST',
            extraData: {

            }
        });
    }

    function jobOff(id) {
        commonRequest({
            url: '/api/quartzJobs/id/' + id + '/jobStatus/0',
            type: 'POST',
            extraData: {

            }
        });
    }
    /*]]>*/
</script>
</body>
</html>